Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / the jucer / src / model / components / jucer_JucerComponentHandler.h
blob66fbb9133e0c459946b4b50234f31af7b0857f6a
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_JUCERCOMPONENTHANDLER_JUCEHEADER__
27 #define __JUCER_JUCERCOMPONENTHANDLER_JUCEHEADER__
29 #include "../../ui/jucer_TestComponent.h"
30 #include "../../properties/jucer_FilePropertyComponent.h"
31 #include "../../properties/jucer_ComponentTextProperty.h"
32 #include "../../ui/jucer_MainWindow.h"
33 #include "jucer_ComponentUndoableAction.h"
36 //==============================================================================
37 /**
39 class JucerComponentHandler : public ComponentTypeHandler
41 public:
42 //==============================================================================
43 JucerComponentHandler()
44 : ComponentTypeHandler ("Jucer Component", "xxx", typeid (TestComponent), 300, 200)
47 //==============================================================================
48 Component* createNewComponent (JucerDocument* doc)
50 return new TestComponent (doc, 0, false);
53 const String getXmlTagName() const throw() { return "JUCERCOMP"; }
55 XmlElement* createXmlFor (Component* comp, const ComponentLayout* layout)
57 TestComponent* const tc = dynamic_cast <TestComponent*> (comp);
59 XmlElement* e = ComponentTypeHandler::createXmlFor (comp, layout);
60 e->setAttribute ("sourceFile", tc->getFilename());
61 e->setAttribute ("constructorParams", tc->getConstructorParams());
63 return e;
66 bool restoreFromXml (const XmlElement& xml, Component* comp, const ComponentLayout* layout)
68 TestComponent* const tc = dynamic_cast <TestComponent*> (comp);
70 if (! ComponentTypeHandler::restoreFromXml (xml, comp, layout))
71 return false;
73 tc->setFilename (xml.getStringAttribute ("sourceFile", tc->getFilename()));
74 tc->setConstructorParams (xml.getStringAttribute ("constructorParams"));
76 return true;
79 const String getClassName (Component* comp) const
81 TestComponent* const tc = dynamic_cast <TestComponent*> (comp);
83 String jucerCompClassName;
85 if (tc->getDocument() != 0)
86 jucerCompClassName = tc->getDocument()->getClassName();
88 if (jucerCompClassName.isEmpty())
89 jucerCompClassName = "Component";
91 return jucerCompClassName;
94 void getEditableProperties (Component* component, JucerDocument& document, Array <PropertyComponent*>& properties)
96 TestComponent* const tc = dynamic_cast <TestComponent*> (component);
98 ComponentTypeHandler::getEditableProperties (component, document, properties);
100 properties.add (new JucerCompFileProperty (tc, document));
101 properties.add (new ConstructorParamsProperty (tc, document));
102 properties.add (new JucerCompOpenDocProperty (tc));
105 const String getCreationParameters (Component* component)
107 TestComponent* const tc = dynamic_cast <TestComponent*> (component);
109 return tc->getConstructorParams().trim();
111 void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
113 ComponentTypeHandler::fillInCreationCode (code, component, memberVariableName);
115 TestComponent* const tc = dynamic_cast <TestComponent*> (component);
117 code.includeFilesH.add (tc->getFilename().replace (".cpp", ".h"));
120 //==============================================================================
121 class JucerCompFileChangeAction : public ComponentUndoableAction <TestComponent>
123 public:
124 JucerCompFileChangeAction (TestComponent* const comp, ComponentLayout& layout, const String& newState_)
125 : ComponentUndoableAction <TestComponent> (comp, layout),
126 newState (newState_)
128 oldState = comp->getFilename();
131 bool perform()
133 showCorrectTab();
134 getComponent()->setFilename (newState);
135 changed();
136 return true;
139 bool undo()
141 showCorrectTab();
142 getComponent()->setFilename (oldState);
143 changed();
144 return true;
147 String newState, oldState;
150 static void setJucerComponentFile (JucerDocument& document, TestComponent* comp, const String& newFilename)
152 jassert (comp != 0);
154 if (comp != 0)
155 document.perform (new JucerCompFileChangeAction (comp, *document.getComponentLayout(), newFilename),
156 "Change Jucer component file");
159 private:
160 //==============================================================================
161 class JucerCompFileProperty : public FilePropertyComponent,
162 public ChangeListener
164 public:
165 JucerCompFileProperty (TestComponent* const component_, JucerDocument& document_)
166 : FilePropertyComponent ("Jucer file", false, true),
167 component (component_),
168 document (document_)
170 document.addChangeListener (this);
173 ~JucerCompFileProperty()
175 document.removeChangeListener (this);
178 //==============================================================================
179 void setFile (const File& newFile)
181 setJucerComponentFile (document, component,
182 newFile.getRelativePathFrom (document.getFile().getParentDirectory())
183 .replaceCharacter ('\\', '/'));
186 const File getFile() const
188 return component->findFile();
191 void changeListenerCallback (ChangeBroadcaster*)
193 refresh();
196 private:
197 TestComponent* const component;
198 JucerDocument& document;
201 //==============================================================================
202 class JucerCompOpenDocProperty : public ButtonPropertyComponent
204 public:
205 JucerCompOpenDocProperty (TestComponent* const component_)
206 : ButtonPropertyComponent ("edit", false),
207 component (component_)
211 void buttonClicked()
213 MainWindow* const mw = findParentComponentOfClass ((MainWindow*) 0);
215 jassert (mw != 0);
216 if (mw != 0)
217 mw->openFile (component->findFile());
220 const String getButtonText() const
222 return "Open file for editing";
225 private:
226 TestComponent* const component;
229 //==============================================================================
230 class ConstructorParamsProperty : public ComponentTextProperty <TestComponent>
232 public:
233 ConstructorParamsProperty (TestComponent* comp, JucerDocument& document)
234 : ComponentTextProperty <TestComponent> ("constructor params", 512, false, comp, document)
238 void setText (const String& newText)
240 document.perform (new ConstructorParamChangeAction (component, *document.getComponentLayout(), newText),
241 "Change Viewport content constructor params");
244 const String getText() const
246 return component->getConstructorParams();
249 private:
250 int tabIndex;
252 class ConstructorParamChangeAction : public ComponentUndoableAction <TestComponent>
254 public:
255 ConstructorParamChangeAction (TestComponent* const comp, ComponentLayout& layout, const String& newValue_)
256 : ComponentUndoableAction <TestComponent> (comp, layout),
257 newValue (newValue_)
259 oldValue = comp->getConstructorParams();
262 bool perform()
264 showCorrectTab();
265 getComponent()->setConstructorParams (newValue);
266 changed();
267 layout.getDocument()->refreshAllPropertyComps();
268 return true;
271 bool undo()
273 showCorrectTab();
274 getComponent()->setConstructorParams (oldValue);
275 changed();
276 layout.getDocument()->refreshAllPropertyComps();
277 return true;
280 String newValue, oldValue;
286 #endif // __JUCER_JUCERCOMPONENTHANDLER_JUCEHEADER__